{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "![](https://raw.githubusercontent.com/Qinbf/tf-model-zoo/master/README_IMG/01.jpg)\n",
    "AI MOOC： **www.ai-xlab.com**  \n",
    "如果你也是AI爱好者，可以添加我的微信一起交流：**sdxxqbf**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.cluster import KMeans\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 载入数据\n",
    "data = np.genfromtxt(\"kmeans.txt\", delimiter=\" \")\n",
    "# 设置k值\n",
    "k = 4  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "KMeans(algorithm='auto', copy_x=True, init='k-means++', max_iter=300,\n",
       "    n_clusters=4, n_init=10, n_jobs=1, precompute_distances='auto',\n",
       "    random_state=None, tol=0.0001, verbose=0)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 训练模型\n",
    "model = KMeans(n_clusters=k)\n",
    "model.fit(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-2.46154315  2.78737555]\n",
      " [ 2.6265299   3.10868015]\n",
      " [-3.38237045 -2.9473363 ]\n",
      " [ 2.80293085 -2.7315146 ]]\n"
     ]
    }
   ],
   "source": [
    "# 分类中心点坐标\n",
    "centers = model.cluster_centers_\n",
    "print(centers)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1\n",
      " 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0\n",
      " 3 2 1 0 3 2]\n"
     ]
    }
   ],
   "source": [
    "# 预测结果\n",
    "result = model.predict(data)\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 0, 3, 2, 1, 0, 3, 2, 1, 0, 3, 2, 1, 0, 3, 2, 1, 0, 3, 2, 1, 0,\n",
       "       3, 2, 1, 0, 3, 2, 1, 0, 3, 2, 1, 0, 3, 2, 1, 0, 3, 2, 1, 0, 3, 2,\n",
       "       1, 0, 3, 2, 1, 0, 3, 2, 1, 0, 3, 2, 1, 0, 3, 2, 1, 0, 3, 2, 1, 0,\n",
       "       3, 2, 1, 0, 3, 2, 1, 0, 3, 2, 1, 0, 3, 2])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.labels_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXYAAAD8CAYAAABjAo9vAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAG2pJREFUeJzt3X9sVNeVB/DvGWMMhgYU4xo14DFu\nWbaIH8kyTUtbqWmTrNKUEqmJsm0dlCZSraStFBSibsHSRmlrNQr9kUqttnJ3iSoxUkOaOCwsVZtA\n0a60ZMXQhhBwQlNi0/SH67BNSmJisOfsH8+D7fGbmTcz78d9930/0sh4/Dxzx/M4c9+5594rqgoi\nIrJHKuoGEBGRvxjYi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yQRWS4ivxKRARE5KSL3Rd2moIlI\ng4j8RkT2R92WejGwB0hElgO4EUASthl6BsAaVV0H4DSA7RG3x1ci0gDghwA+CWA1gM+JyOpoWxWo\ncQDbVPX9AD4E4MuWv14AuA/AQNSN8AMDe7C+B+CrAKwfyFDVX6rq+OS3zwFYFmV7AnAtgFdU9Yyq\nXgTwUwC3RNymwKjqn1T115P/Pg8n4F0VbauCIyLLAHwKwL9F3RY/MLAHREQ2A/iDqh6Pui0RuBvA\nz6NuhM+uAvD7ad+/BosD3XQi0gHgGgD/G21LAvUonE5YPuqG+IGbWddBRJ4FsNTlRz0AdgD4x3Bb\nFKxyr1dV904e0wPnMj4bZttCIC73WX8lJiILATwJYKuq/i3q9gRBRDYB+IuqHhOR66Jujx8Y2Oug\nqje43S8iawGsAHBcRAAnLfFrEblWVf8cYhN9Ver1FojInQA2Abhe7aujfQ3A8mnfLwPwx4jaEgoR\naYQT1LOq+lTU7QnQRwBsFpGbAcwDcIWI7FbVOyJuV81Yxx4CERkEkFFVkxcXqouI3ATguwA+pqoj\nUbfHbyIyB86g8PUA/gDgKIDPq+rJSBsWEHF6JD8B8H+qujXq9oRlssf+gKpuirot9WCOnfzyAwDv\nAvCMiDwvIj+KukF+mhwY/gqAX8AZSNxja1Cf9BEAWwB8YvL9fH6yR0sxwB47EZFl2GMnIrIMAzsR\nkWUY2ImILMPATkRkGQZ2IiLLMLATEVmGgZ2IyDIM7ERElvl/bEP4zCLOKkcAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1e8255a37f0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画出各个数据点，用不同颜色表示分类\n",
    "mark = ['or', 'ob', 'og', 'oy']\n",
    "for i,d in enumerate(data):\n",
    "    plt.plot(d[0], d[1], mark[result[i]])\n",
    "\n",
    "# 画出各个分类的中心点\n",
    "mark = ['*r', '*b', '*g', '*y']\n",
    "for i,center in enumerate(centers):\n",
    "    plt.plot(center[0],center[1], mark[i], markersize=20)\n",
    "    \n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXYAAAD8CAYAAABjAo9vAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAH5VJREFUeJzt3XuQXOV5JvDn7e4ZzYx6LpqLhMUg\nIaRIhthURMY2AYQFmIuBmI0LVzlUXCZOreJs7GDHl9hhK7v/hVq7YlOVeDcKJIpjXI7LIeVsiCNB\nMCysF2KJSxxZgpWEBgYJjS5zv8/0mz/6op6Zvpzu850+3/nO86ui0PS0ur8B6Tlfv+c97xFVBRER\nuSMR9gKIiMgsBjsRkWMY7EREjmGwExE5hsFOROQYBjsRkWMY7EREjmGwExE5hsFOROSYlIkXEZEu\nAI8AeA8ABfApVf1/5Z7fnGjV1mS7ibcmCtRi15qwl0BUMH1u6Jyq9lV7npFgB/AwgH9W1XtFpBlA\nW6UntybbcV3vxwy9NVFw5t/dj7GtDHeyw6FHvzDo5Xm+g11EOgDcCOB+AFDVeQDzfl+XiIjqY6LG\nfgWAswD+SkReFpFHRGStgdclIqI6mAj2FIBrAPxPVd0JYArAV1Y+SUT2iMhBETk4n5kx8LZERFSK\niWAfAjCkqi/mvv4BskG/jKruVdUBVR1oTrQaeFsiIirFd7Cr6jsA3hKRHbmHbgHwc7+vS0RE9THV\nFfNZAI/lOmJOAPhNQ69LFKrmo0PA1q1hL4OoJkaCXVVfATBg4rWIiMgfXnlKROQYBjsRkWMY7ERE\njmGwExE5hsFOROQYBjtRFX1PHA97CUQ1YbATETnG1AVKRBQh54/twKmDuzA/1Y7mtRPYOPAcera9\nFvayyBAGO1HMnD+2A4PP3wZdagI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edo3rkP2Y+D4A3xeRKzQi7TxVfrY/BHBbY1dkTqWfTVV/mHvOg8h+3H+skWsLgJR4\nLBJ/Br0QkTSAvwPwOVUdD3s9JojI3QCGVfWQiOwOez2NZEWwq+qHyn1PRH4HwOO5IP9XEckgO/fh\nbKPW50e5n01E3gtgC4BXRQTIlipeEpH3q+o7DVxi3Sr9fwMAEfkkgLsB3BKVA3EFQwAuK/q6H8Cp\nkNZilIg0IRvqj6nq42Gvx6DrAXxERO4E0AKgQ0S+o6q/EfK6Amd9H7uIfBrARlX9IxHZDuBfAGxy\nICiWEZGTAAZU1YVBRRCROwD8CYAPqmokDsKViEgK2ZPAtwB4G8BPAdynqodDXZhPkt1V/DWAC6r6\nubDXE5Tcjv2Lqnp32GtphCjU2P8SwBUi8u/InrD6pGuh7qg/BdAO4EkReUVE/lfYC/IjdyL4MwD2\nI3uC8ftRD/Wc6wF8AsDNuf9Pr+R2uBRh1u/YiYioNlHYsRMRUQ0Y7EREjmGwExE5hsFOROQYBjsR\nkWMY7EREjmGwExE5hsFOROSY/wB6zY1cP3W/yAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1e8245916a0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 获取数据值所在的范围\n",
    "x_min, x_max = data[:, 0].min() - 1, data[:, 0].max() + 1\n",
    "y_min, y_max = data[:, 1].min() - 1, data[:, 1].max() + 1\n",
    "\n",
    "# 生成网格矩阵\n",
    "xx, yy = np.meshgrid(np.arange(x_min, x_max, 0.02),\n",
    "                     np.arange(y_min, y_max, 0.02))\n",
    "\n",
    "z = model.predict(np.c_[xx.ravel(), yy.ravel()])# ravel与flatten类似，多维数据转一维。flatten不会改变原始数据，ravel会改变原始数据\n",
    "z = z.reshape(xx.shape)\n",
    "# 等高线图\n",
    "cs = plt.contourf(xx, yy, z)\n",
    "# 显示结果\n",
    "# 画出各个数据点，用不同颜色表示分类\n",
    "mark = ['or', 'ob', 'og', 'oy']\n",
    "for i,d in enumerate(data):\n",
    "    plt.plot(d[0], d[1], mark[result[i]])\n",
    "\n",
    "# 画出各个分类的中心点\n",
    "mark = ['*r', '*b', '*g', '*y']\n",
    "for i,center in enumerate(centers):\n",
    "    plt.plot(center[0],center[1], mark[i], markersize=20)\n",
    "    \n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
